<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;

class FenleiController extends Controller
{
      public function index(){
         $data = DB::table('fenlei')->orderBy('id', 'desc')->paginate(15);
         return view('admin.fenlei.index',compact('data'));
      }

      public function create(){
         return view('admin.fenlei.add');
      }

      //编辑视图
      public function edit($id){


      $data = DB::table('fenlei')->where('id',$id)->first();

        return view('admin.fenlei.edit',compact('data'));
      }



//更新提交
    public function update(Request $request,$id){

      $res = DB::table('fenlei')->where('id',$id)->update([
            'name' => $request->name,
        ]);
      if ($res == 1) {
         return redirect('admin/fen');
      }else{
        return back()->with('更新失败！');
      }
    }

       //删除
      public function destroy($id)
    {

      $post = DB::table('fenlei')->where('id', $id)->delete();
      return  $data = ['status' => 0,'msg' => '删除成功！'];
    }


//搜索提交
    public function store(Request $request){
          $name = $request->name;
          $data = DB::table('fenlei')->insert(['name'=>$name,'created_at'=>time()]);
          return redirect('admin/fen');
    }

}
